var sortTypeId="";
var propertyTypeId="";
var allSort="";
var addTimeSort="";
var gPriceSort="";
var dPriceSort="";
var collectNumSort="";
var saleNumSort="";
var fenleiId="";
var shuxinId="";
var priceId=1;
var shangquanid="";
function  TwoclassificationShuxin2(){
	$("#wage span").text("全部属性");
	shuxinId="";
		currentPage=1;
	$("#chanping").html("");
	selectRemai();
	$(".retrie dt a").removeClass('up');
	$('.downlist').hide();
}


//remai("","","","","","","","","");
//分类
function fenlei(){
	$("#sortUl").html("");
     $.ajax({
			url: urlcore + "/api/sortType/Primaryclassification?coder=2",
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success:function(data){
				 var suns=0;
				 var sortUl="";
           	$.each(data.data.sortTypeList,function(i,n){
           		suns++;
           		 if(suns==1){
sortUl+='<li><a href="javascript:TwoclassificationFenlei2();">全部分类</a></li>'; 
				  }
 sortUl+='<li><a href="javascript:TwoclassificationFenlei('+n.id+');">'+n.sortName+'</a></li>'; 
           	});
           	$("#sortUl").append(sortUl);
			}, 
			error:function() {
				/* Act on the event*/    //商品类别已完结
				alert("error");
			}
		});
}

function TwoclassificationFenlei(str){
	 	$("#sortSon").html("");
	    $.ajax({
			url: urlcore + "/api/sortType/TwoGoodsAlls?id="+str,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success:function(data){
           	
           	$.each(data.data,function(g,h){
    var Fenleierji='<li id="'+h.id+'"><a href="javascript:selectChanPinByfenlei('+h.id+',\''+h.sortName+'\');">'+h.sortName+'</a></li>';
           			$("#sortSon").append(Fenleierji);
           	});
           
			}, 
			error:function() {
				/* Act on the event*/    //商品类别已完结
				alert("error");
			}
		});
}

function TwoclassificationFenlei2(){
	$("#area span").text("全部分类");
	fenleiId="";
	 $('#qiugou').html("");
	 currentPage=1;
	selectRemai();
	$(".retrie dt a").removeClass('up');
	$('.downlist').hide();
}

///------------------------------------分类



function shuxin(){
	$("#fengge").html("");
     $.ajax({
			url: urlcore + "/api/sortType/Primaryclassification?coder=1",
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success:function(data){
           	 var fengge="";
           	var conut=0;
           	$.each(data.data.propertyTypeList,function(g,h){
           		conut++;
           		if(conut==1){
               fengge+='<li class="w_on1"><a href="javascript:TwoclassificationShuxin2();">全部属性</a></li>';
           		}
           	   fengge+='<li><a href="javascript:TwoclassificationShuxin('+h.id+');">'+h.propertyName+'</a></li>';

           	});
           		$("#fengge").append(fengge);
			}, 
			error:function() {
				/* Act on the event*/ 
				alert("error");
			}
		});
}

function TwoclassificationShuxin(str){
	 	$("#erji").html("");
	    $.ajax({
			url: urlcore + "/api/sortType/Twoclassification?id="+str,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success:function(data){
           	var conut=0;
           	var erji="";
           	$.each(data.data,function(g,h){
           		conut++;
           		if(conut==1){
           		 erji='<li class="shu_curr" id="'+h.id+'"><a href="javascript:selectChanPinByShuxin('+h.id+',\''+h.propertyName+'\');">'+h.propertyName+'</a></li>';
           		}else{
           		erji+='<li id="'+h.id+'"><a href="javascript:selectChanPinByShuxin('+h.id+',\''+h.propertyName+'\');">'+h.propertyName+'</a></li>';
           			
           		}
           	});
           	   erji+='<li id="">其他</li>';
           	$("#erji").append(erji);
			}, 
			error:function() {
				/* Act on the event*/    //商品类别已完结
				alert("error");
			}
		});
}

function selectChanPinByfenlei(id,name){
	$("#area span").text(name);
	fenleiId=id;
		$("#chanping").html("");
	currentPage=1;
	selectRemai();
	$(".retrie dt a").removeClass('up');
	$('.downlist').hide();
}
function  selectChanPinByShuxin(id,name){
	$("#wage span").text(name);
	shuxinId=id;
		$("#chanping").html("");
	currentPage=1;
	selectRemai();
	$(".retrie dt a").removeClass('up');
	$('.downlist').hide();
}
function selectChanPinByprice(id,name){
	$("#price span").text(name);
	priceId=id;
	$("#chanping").html("");
	currentPage=1;
	selectRemai();
	$(".retrie dt a").removeClass('up');
	$('.downlist').hide();
}
//根据条件查询热卖信息
$(function(){
	selectRemai();
})


var ss=0;

function selectRemai(){
	if(currentPage==1 || currentPage==2 || ss!=0){
	$.ajax({
       url: urlcore + "/api/goods/selectGoodsListByCondition?current="+currentPage+"&tradeNumber=1&sortTypeId="+fenleiId+"&propertyTypeId="+shuxinId+"&sort="+priceId+"&tradeAreaId="+shangquanid,
        type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
				//alert(JSON.stringify(data.data.list));
				ss=data.data.list.length;
				
				  $.each(data.data.list,function(y,n){
				  	    var chanping='<div class="public_goods">'+
			           '<a href="7.0.0goods_detail.html?id='+n.id+'">'+
				'<dl>'+
					'<dt>'+
						'<img onerror="errorImg(this)" src="'+n.coverUrl+'"/>'+
					'</dt>'+
					'<dd>'+
						'<h5>'+n.goodsTitle+'</h5>'+
						'<h6>&yen;'+n.packPrice+'</h6>'+ /*yen;'+n.tradePrice+'-' +*/
					'</dd>'+
				'</dl>'+
			'</a>'+
		'</div>';
				  	  $("#chanping").append(chanping);
				  });
			} else if(data.code == 'OVERTIME') {
				var thisUrl = window.location.href;
				alert(thisUrl);
				if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
					top.window.location.href = "1.0.0denglu.html";
				}

			} else {
				if(data.msg != '空数据') {
					alert(data.msg)
				} else {
					$('#thiscount').text(0);
				}
			}

		},
		error: function() {
			alert("error");
		}
	});
	}
}

var currentPage=1;
function remai(){	
	$(document).ready(function() {
		init(currentPage);
	});
	function init(pageNo) {
		$("#chanping").html("");
		$.ajax({
           url: urlcore + "/api/goods/selectGoodsListByCondition?current="+pageNo+"&goodsType=3",
            type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					//alert(JSON.stringify(data.data.list));
					  $.each(data.data.list,function(y,n){
					  	    var chanping='<div class="public_goods">'+
				           '<a href="7.0.0goods_detail.html?id='+n.id+'">'+
					'<dl>'+
						'<dt>'+
							'<img onerror="errorImg(this)" src="'+n.coverUrl+'"/>'+
						'</dt>'+
						'<dd>'+
							'<h5>'+n.goodsTitle+'</h5>'+
							'<h6>&yen;'+n.tradePrice+'-' +'&yen;'+n.packPrice+'</h6>'+
						'</dd>'+
					'</dl>'+
				'</a>'+
			'</div>';
					  	  $("#chanping").append(chanping);
					  });
				} else if(data.code == 'OVERTIME') {
					var thisUrl = window.location.href;
					alert(thisUrl);
					if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
						top.window.location.href = "1.0.0denglu.html";
					}

				} else {
					if(data.msg != '空数据') {
						alert(data.msg)
					} else {
						$('#thiscount').text(0);
					}
				}

			},
			error: function() {
				alert("error");
			}
		});
	}
	PageClick = function(pageclickednumber) {
		init(pageclickednumber);
	}
}




 function shangquan(){
 	  $("#shangquan").html("");	
    	 $.ajax({
             url: urlcore + "/api/tradeArea/selectList",
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
				var suns=0;
				var shangquan="";
					  $.each(data.data,function(y,n){
					  	suns++;
					  	if(suns==1){
				 shangquan+='<li  onclick="selsetshangquan2()">全部商圈</li> ';
                
					  	}
 shangquan+='<li  onclick="selsetshangquan('+n.id+',\''+n.areaName+'\')">'+n.areaName+'</li> ';
                    	
					  });
					    $("#shangquan").append(shangquan);					  
				} else if(data.code == 'OVERTIME') {
					var thisUrl = window.location.href;
					alert(thisUrl);
					if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
						top.window.location.href = "1.0.0denglu.html";
					}
				} else {
					if(data.msg != '空数据') {
						alert(data.msg)
					} else {
						$('#thiscount').text(0);
					}
				}
			},
			error: function() {
				alert("error");
			}
		});	
    }
 


 
 function selsetshangquan(id,name){
 
	//alert("..."+name);
	$("#shangquanmingzi").html("");
	$("#shangquanmingzi").html(name);
	shangquanid=id;
	
	//$("#pfsq span").removeClass('up');
	$('#shangquan').hide();
currentPage=1;
$("#chanping").html("");
selectRemai();
 	
 	
 }
 
 

 function selsetshangquan2(){
	//alert("..."+name);
	$("#shangquanmingzi").html("");
	$("#shangquanmingzi").html("全部商圈");
	shangquanid="";
	
	//$("#pfsq span").removeClass('up');
	$('#shangquan').hide();
currentPage=1;
$("#chanping").html("");
selectRemai();
 }
 
